package qf.sail.controller;

import qf.sail.entity.Account;
import qf.sail.entity.Order;
import qf.sail.service.OrderService;
import qf.sail.service.impl.OrderServiceImpl;
import qf.sail.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getOrderList")
public class getOrderListServlet extends BaseServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        OrderService orderService = new OrderServiceImpl();
        int page = Integer.parseInt(req.getParameter("page"));
        Account account = (Account) req.getSession().getAttribute("account");

        List<Order> orders = orderService.getOrderList(account.getId(),page);

        //计算总页面
        int pages = (orderService.getCountById(account.getId())/5)+1;

        ResultVO resultVO = new ResultVO();
        resultVO.addData("pages",pages);
        resultVO.addData("orders",orders);

        repSuccess(resp,resultVO);

    }
}

